package dongtai;

import java.util.List;

public class yisanjiu {
    public static boolean wordBreak(String s, List<String> wordDict) {
        int n=s.length();
        //初始值为false
        boolean[] f=new boolean[n+1];
        f[0]=true;
        //技巧 使得s的下标与f的下标可以一一对应
        s=" "+s;
        //填写f[i],从1开始
        for(int i=1;i<n+1;i++){
            //考虑最后一个单词的情况
            for(int j=1;j<=i;j++){
                if(f[j-1]&&wordDict.contains(s.substring(j, i+1))){
                    f[i]=true;
                    break;
                }
            }
        }
        return f[n];
    }

    public static void main(String[] args) {
            String s = "a";
        String[] wordDict ={"a"};
        boolean b = wordBreak(s, List.of(wordDict));
        System.out.println(b);


    }
}
